package com.wandian.ui.controls
{
	import flash.text.TextField;
	import flash.text.TextFormat;
	import com.wandian.ui.controls.Button;


	public class LabelButton extends Button
	{
		private var textField:TextField
		private var textFormat:TextFormat

		public function LabelButton(w:int=100, h:int=32)
		{

			super(w, h);
		}

		override protected function createChildren():void
		{
			super.createChildren()
			textField=new TextField();
			textFormat=new TextFormat();
			textFormat.size=getStyle("fontSize")
			textFormat.font=getStyle("fontFamily")
			textFormat.bold=getStyle("fontWeight")
			textFormat.align=getStyle("textAlign")
			textField.defaultTextFormat=textFormat;
			this.addChild(textField)
		}

		public function set label(v:String):void
		{

			textField.text=v
			adjustTextField();
		}

		public function get label():String
		{
			return textField.text
		}


		override protected function updatePhaseDisplay(w:int, h:int):void
		{
			super.updatePhaseDisplay(w, h)
			switch (phase)
			{
				case "up":
				{
					textFormat.color=getStyle("textColor")
					break
				}
				case "over":
				{
					textFormat.color=getStyle("textRollOverColor")
					break
				}
				case "down":
				{
					textFormat.color=getStyle("textSelectedColor")
					break
				}
			}
			textField.setTextFormat(textFormat);
		}

		override protected function layoutContents(w:int, h:int):void
		{
			adjustTextField()
		}

		private function adjustTextField():void
		{
			textField.autoSize="left"
			var th:Number=textField.height
			textField.autoSize="none"
			textField.width=this.width;
			textField.height=th;
			textField.y=int((height - th) / 2);
		}

		override protected function styleChanged(key:String, v:*):void
		{
			switch (key)
			{
				case "fontSize":
					break;
			}
		}
	}
}
